package com.ling.sbbyyds.common.validator;

import java.lang.reflect.Constructor;

/**
 * 校验工具类
 *
 * @author ling
 */
public class ValidatorUtils {

    /**
     * 是否抛出异常
     * @param isTrue 是否异常
     * @return 函数体
     */
    public static ThrowExceptionFunction isException(boolean isTrue) {
        return (message, exceptionType) -> {
            if (isTrue) {
                Constructor<? extends Throwable> constructor = exceptionType.getConstructor(String.class);
                throw constructor.newInstance(message);
            }
        };
    }
}
